"""
@Project ：TeachingInterfacePro 
@File    ：LoginApi.py
@IDE     ：PyCharm 
@Author  ：ceiling
@Date    ：2025/4/17 21:52 
"""
import os

import requests

from api import BASE_URL
from conftest import BASE_DIR
from utils.LoadEnvUtil import LoadEnvUtil


class LoginApi:

    def __init__(self):
        self.nev_file = BASE_DIR + os.sep + ".env"
        self.url = BASE_URL + "/account/token"

    def login(self, name, password):

        body = {
            "name": name,
            "password": password
        }

        response = requests.post(url=self.url, json=body)
        data = response.json()["data"]
        LoadEnvUtil.set_env_params(self.nev_file, "COOKIE", data)
        return response
